<?php
function pagination($page,$allCount,$pageSize=30,$eachPage=10)
{
    $pageCount=intval($allCount/$pageSize);
    if($allCount%$pageSize>0){
        $pageCount++;
    }

    if($page<1){
        $page=1;
    }

    if($page>$pageCount){
        $page=$pageCount;
    }

    $fromPage=intval(($page-1)/$eachPage)*$eachPage+1;
    $toPage=$fromPage+$eachPage-1;

    $prevPage=$page-1;
    $nextPage=$page+1;

    if($fromPage<1){$fromPage=1;}
    if($toPage>$pageCount){$toPage=$pageCount;}

    if($prevPage<1){$prevPage=1;}
    if($nextPage>$pageCount){$nextPage=$pageCount;}

    $pageData=array(
        'page'=>$page,
        'allCount'=>$allCount,
        'pageCount'=>$pageCount,
        'pageSize'=>$pageSize,
        'fromPage'=>$fromPage,
        'toPage'=>$toPage,
        'prevPage'=>$prevPage,
        'nextPage'=>$nextPage
    );

    return $pageData;
}


function tbs_new_encode($str)
{
    $key='tbs!1234888dsfsdfsdlfjsdklfjsdklfjlxxm01';
    $key=substr(md5($key),8,8);
    $str= Org\Net\Encoder::encodeData($str,$key);
    return $str;
}

function tbs_new_decode($str)
{
    $key='tbs!1234888dsfsdfsdlfjsdklfjsdklfjlxxm01';
    $key=substr(md5($key),8,8);
    $str= Org\Net\Encoder::decodeData($str,$key);
    return $str;
}

 function syssubstr($string,$start,$length){
    return mb_substr($string,$start,$length);
}

 function title ($string){
     $pos = mb_strpos ($string,'_土拨鼠');
    if($pos != false ){
        return mb_substr($string,0,$pos);
    }
    return $string;
}
